package com.smartbone.dao.daoImplemetation;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.support.JpaDaoSupport;

import com.smartbone.dao.daoInterface.IFinanceDAO;
import com.smartbone.entity.Finance;

/**
 * A data access object (DAO) providing persistence and search support for
 * Finance entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.Finance
 * @author MyEclipse Persistence Tools
 */

public class FinanceDAO extends JpaDaoSupport implements IFinanceDAO {
	// property constants
	public static final String MGSY = "mgsy";
	public static final String MGJZC = "mgjzc";
	public static final String JZCSYL = "jzcsyl";
	public static final String MGJYXJ = "mgjyxj";
	public static final String MGGJJ = "mggjj";
	public static final String MGWFP = "mgwfp";
	public static final String GDQYB = "gdqyb";
	public static final String JLRTB = "jlrtb";
	public static final String ZYSLTB = "zysltb";
	public static final String XSMLL = "xsmll";
	public static final String TZMGJZC = "tzmgjzc";
	public static final String ZZC = "zzc";
	public static final String LDZC = "ldzc";
	public static final String GDZC = "gdzc";
	public static final String WXZC = "wxzc";
	public static final String LDFZ = "ldfz";
	public static final String CQFZ = "cqfz";
	public static final String ZFZ = "zfz";
	public static final String GDQY = "gdqy";
	public static final String ZBGJJ = "zbgjj";
	public static final String JYXJLL = "jyxjll";
	public static final String TZXJLL = "tzxjll";
	public static final String CZXJLL = "czxjll";
	public static final String XJZJE = "xjzje";
	public static final String ZYSR = "zysr";
	public static final String ZYLR = "zylr";
	public static final String YYLR = "yylr";
	public static final String TZSY = "tzsy";
	public static final String YYWSZ = "yywsz";
	public static final String LRZE = "lrze";
	public static final String JLR = "jlr";
	public static final String WFPLR = "wfplr";
	public static final String AG = "ag";

	/**
	 * Perform an initial save of a previously unsaved Finance entity. All
	 * subsequent persist actions of this entity should use the #update()
	 * method. This operation must be performed within the a database
	 * transaction context for the entity's data to be permanently saved to the
	 * persistence store, i.e., database. This method uses the
	 * {@link javax.persistence.EntityManager#persist(Object)
	 * EntityManager#persist} operation.
	 * <p>
	 * User-managed Spring transaction example:
	 * 
	 * <pre>
	 * TransactionStatus txn = txManager
	 * 		.getTransaction(new DefaultTransactionDefinition());
	 * FinanceDAO.save(entity);
	 * txManager.commit(txn);
	 * </pre>
	 * 
	 * @see <a href =
	 *      "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
	 *      container-managed transaction examples</a>
	 * @param entity
	 *            Finance entity to persist
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void save(Finance entity) {
		logger.info("saving Finance instance");
		try {
			getJpaTemplate().persist(entity);
			logger.info("save successful");
		} catch (RuntimeException re) {
			logger.error("save failed", re);
			throw re;
		}
	}

	/**
	 * Delete a persistent Finance entity. This operation must be performed
	 * within the a database transaction context for the entity's data to be
	 * permanently deleted from the persistence store, i.e., database. This
	 * method uses the {@link javax.persistence.EntityManager#remove(Object)
	 * EntityManager#delete} operation.
	 * <p>
	 * User-managed Spring transaction example:
	 * 
	 * <pre>
	 * TransactionStatus txn = txManager
	 * 		.getTransaction(new DefaultTransactionDefinition());
	 * FinanceDAO.delete(entity);
	 * txManager.commit(txn);
	 * entity = null;
	 * </pre>
	 * 
	 * @see <a href =
	 *      "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
	 *      container-managed transaction examples</a>
	 * @param entity
	 *            Finance entity to delete
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void delete(Finance entity) {
		logger.info("deleting Finance instance");
		try {
			entity = getJpaTemplate().getReference(Finance.class,
					entity.getId());
			getJpaTemplate().remove(entity);
			logger.info("delete successful");
		} catch (RuntimeException re) {
			logger.error("delete failed", re);
			throw re;
		}
	}

	/**
	 * Persist a previously saved Finance entity and return it or a copy of it
	 * to the sender. A copy of the Finance entity parameter is returned when
	 * the JPA persistence mechanism has not previously been tracking the
	 * updated entity. This operation must be performed within the a database
	 * transaction context for the entity's data to be permanently saved to the
	 * persistence store, i.e., database. This method uses the
	 * {@link javax.persistence.EntityManager#merge(Object) EntityManager#merge}
	 * operation.
	 * <p>
	 * User-managed Spring transaction example:
	 * 
	 * <pre>
	 * TransactionStatus txn = txManager
	 * 		.getTransaction(new DefaultTransactionDefinition());
	 * entity = FinanceDAO.update(entity);
	 * txManager.commit(txn);
	 * </pre>
	 * 
	 * @see <a href =
	 *      "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
	 *      container-managed transaction examples</a>
	 * @param entity
	 *            Finance entity to update
	 * @return Finance the persisted Finance entity instance, may not be the
	 *         same
	 * @throws RuntimeException
	 *             if the operation fails
	 */
	public Finance update(Finance entity) {
		logger.info("updating Finance instance");
		try {
			Finance result = getJpaTemplate().merge(entity);
			logger.info("update successful");
			return result;
		} catch (RuntimeException re) {
			logger.error("update failed", re);
			throw re;
		}
	}

	public Finance findById(Long id) {
		logger.info("finding Finance instance with id: " + id);
		try {
			Finance instance = getJpaTemplate().find(Finance.class, id);
			return instance;
		} catch (RuntimeException re) {
			logger.error("find failed", re);
			throw re;
		}
	}

	/**
	 * Find all Finance entities with a specific property value.
	 * 
	 * @param propertyName
	 *            the name of the Finance property to query
	 * @param value
	 *            the property value to match
	 * @return List<Finance> found by query
	 */
	@SuppressWarnings("unchecked")
	public List<Finance> findByProperty(String propertyName, final Object value) {
		logger.info("finding Finance instance with property: " + propertyName
				+ ", value: " + value);
		try {
			final String queryString = "select model from Finance model where model."
					+ propertyName + "= :propertyValue";
			return getJpaTemplate().executeFind(new JpaCallback() {
				public Object doInJpa(EntityManager em)
						throws PersistenceException {
					Query query = em.createQuery(queryString);
					query.setParameter("propertyValue", value);
					return query.getResultList();
				}
			});
		} catch (RuntimeException re) {
			logger.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Finance> findByMgsy(Object mgsy) {
		return findByProperty(MGSY, mgsy);
	}

	public List<Finance> findByMgjzc(Object mgjzc) {
		return findByProperty(MGJZC, mgjzc);
	}

	public List<Finance> findByJzcsyl(Object jzcsyl) {
		return findByProperty(JZCSYL, jzcsyl);
	}

	public List<Finance> findByMgjyxj(Object mgjyxj) {
		return findByProperty(MGJYXJ, mgjyxj);
	}

	public List<Finance> findByMggjj(Object mggjj) {
		return findByProperty(MGGJJ, mggjj);
	}

	public List<Finance> findByMgwfp(Object mgwfp) {
		return findByProperty(MGWFP, mgwfp);
	}

	public List<Finance> findByGdqyb(Object gdqyb) {
		return findByProperty(GDQYB, gdqyb);
	}

	public List<Finance> findByJlrtb(Object jlrtb) {
		return findByProperty(JLRTB, jlrtb);
	}

	public List<Finance> findByZysltb(Object zysltb) {
		return findByProperty(ZYSLTB, zysltb);
	}

	public List<Finance> findByXsmll(Object xsmll) {
		return findByProperty(XSMLL, xsmll);
	}

	public List<Finance> findByTzmgjzc(Object tzmgjzc) {
		return findByProperty(TZMGJZC, tzmgjzc);
	}

	public List<Finance> findByZzc(Object zzc) {
		return findByProperty(ZZC, zzc);
	}

	public List<Finance> findByLdzc(Object ldzc) {
		return findByProperty(LDZC, ldzc);
	}

	public List<Finance> findByGdzc(Object gdzc) {
		return findByProperty(GDZC, gdzc);
	}

	public List<Finance> findByWxzc(Object wxzc) {
		return findByProperty(WXZC, wxzc);
	}

	public List<Finance> findByLdfz(Object ldfz) {
		return findByProperty(LDFZ, ldfz);
	}

	public List<Finance> findByCqfz(Object cqfz) {
		return findByProperty(CQFZ, cqfz);
	}

	public List<Finance> findByZfz(Object zfz) {
		return findByProperty(ZFZ, zfz);
	}

	public List<Finance> findByGdqy(Object gdqy) {
		return findByProperty(GDQY, gdqy);
	}

	public List<Finance> findByZbgjj(Object zbgjj) {
		return findByProperty(ZBGJJ, zbgjj);
	}

	public List<Finance> findByJyxjll(Object jyxjll) {
		return findByProperty(JYXJLL, jyxjll);
	}

	public List<Finance> findByTzxjll(Object tzxjll) {
		return findByProperty(TZXJLL, tzxjll);
	}

	public List<Finance> findByCzxjll(Object czxjll) {
		return findByProperty(CZXJLL, czxjll);
	}

	public List<Finance> findByXjzje(Object xjzje) {
		return findByProperty(XJZJE, xjzje);
	}

	public List<Finance> findByZysr(Object zysr) {
		return findByProperty(ZYSR, zysr);
	}

	public List<Finance> findByZylr(Object zylr) {
		return findByProperty(ZYLR, zylr);
	}

	public List<Finance> findByYylr(Object yylr) {
		return findByProperty(YYLR, yylr);
	}

	public List<Finance> findByTzsy(Object tzsy) {
		return findByProperty(TZSY, tzsy);
	}

	public List<Finance> findByYywsz(Object yywsz) {
		return findByProperty(YYWSZ, yywsz);
	}

	public List<Finance> findByLrze(Object lrze) {
		return findByProperty(LRZE, lrze);
	}

	public List<Finance> findByJlr(Object jlr) {
		return findByProperty(JLR, jlr);
	}

	public List<Finance> findByWfplr(Object wfplr) {
		return findByProperty(WFPLR, wfplr);
	}

	public List<Finance> findByAg(Object ag) {
		return findByProperty(AG, ag);
	}

	/**
	 * Find all Finance entities.
	 * 
	 * @return List<Finance> all Finance entities
	 */
	@SuppressWarnings("unchecked")
	public List<Finance> findAll() {
		logger.info("finding all Finance instances");
		try {
			final String queryString = "select model from Finance model";
			return getJpaTemplate().executeFind(new JpaCallback() {
				public Object doInJpa(EntityManager em)
						throws PersistenceException {
					Query query = em.createQuery(queryString);
					return query.getResultList();
				}
			});
		} catch (RuntimeException re) {
			logger.error("find all failed", re);
			throw re;
		}
	}

	public static IFinanceDAO getFromApplicationContext(ApplicationContext ctx) {
		return (IFinanceDAO) ctx.getBean("FinanceDAO");
	}
}